﻿
// DevilMayCry4_DX9Dlg.cpp : 实现文件
//

#include "stdafx.h"
#include "DevilMayCry4_DX9.h"
#include "DevilMayCry4_DX9Dlg.h"
#include "afxdialogex.h"
#include "DMC4.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

void SetHook();
void StopHook();
DMC4 dmc;
// CDevilMayCry4_DX9Dlg 对话框

//#pragma comment(lib,"..\\Release\\D3D9.lib")


CDevilMayCry4_DX9Dlg::CDevilMayCry4_DX9Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDevilMayCry4_DX9Dlg::IDD, pParent)
	, exitBP(1)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDevilMayCry4_DX9Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BP, cBP);
	DDX_Control(pDX, IDC_HARD, cHARD);
	DDX_Control(pDX, IDC_MISSION, cBOSS);
	DDX_Text(pDX, IDC_EDITBP, exitBP);
	DDV_MinMaxByte(pDX, exitBP, 1, 101);
	DDX_Control(pDX, IDC_ACT, sAction);
}

BEGIN_MESSAGE_MAP(CDevilMayCry4_DX9Dlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_CBN_SELCHANGE(IDC_BP, &CDevilMayCry4_DX9Dlg::OnChangeBp)
	ON_CBN_SELCHANGE(IDC_HARD, &CDevilMayCry4_DX9Dlg::OnChangeHard)
	ON_CBN_SELCHANGE(IDC_MISSION, &CDevilMayCry4_DX9Dlg::OnCMission)
	ON_WM_DESTROY()
	ON_EN_CHANGE(IDC_EDITBP, &CDevilMayCry4_DX9Dlg::OnEnChangeEditBP)
	ON_BN_CLICKED(IDC_BHELP, &CDevilMayCry4_DX9Dlg::OnBnClickedHelp)
END_MESSAGE_MAP()


void CDevilMayCry4_DX9Dlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CDevilMayCry4_DX9Dlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

BOOL CDevilMayCry4_DX9Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	dmc.psAct=&sAction;

	cBP.AddString(L"正常血宫模式");
	cBP.AddString(L"BOSS  RUSH_MODE");
	cBP.SetCurSel(0);

	cHARD.AddString(L"游戏默认(游戏难度)");
	cHARD.AddString(L"DANTE MUST DIE");
	cHARD.AddString(L"SPARDA MUST DIE");
	cHARD.AddString(L"GOD MUST DIE");
	cHARD.AddString(L"练习模式     ");
	cHARD.SetCurSel(0);

	cBOSS.AddString(L"正常场景");
	cBOSS.AddString(L"替换关卡");
	cBOSS.AddString(L"直接BOSS");
	cBOSS.SetCurSel(0);

	CSpinButtonCtrl *BpSpin=(CSpinButtonCtrl*)GetDlgItem(IDC_SPINBP);
	CEdit *BpEdit=(CEdit*)GetDlgItem(IDC_EDITBP);
	BpSpin->SetBuddy(BpEdit);
	BpSpin->SetRange(1,101);


	if(!dmc.OpenDMC())
		MessageBox(L"游戏未运行！！");
	SetHook();
	dmc.CreateCamera();
	dmc.CreateSpeed();

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

void CDevilMayCry4_DX9Dlg::OnChangeBp()
{
	dmc.SetBpRush(cBP.GetCurSel());
}

void CDevilMayCry4_DX9Dlg::OnChangeHard()
{
	dmc.SetHard(cHARD.GetCurSel());
}

void CDevilMayCry4_DX9Dlg::OnCMission()
{
	dmc.SetMisson(cBOSS.GetCurSel());
}

HHOOK hHook=NULL;
LRESULT CALLBACK KeyProc(int nCode,WPARAM wParam,LPARAM lParam)
{
	PKBDLLHOOKSTRUCT l=(KBDLLHOOKSTRUCT*)lParam;
	HWND hwnd=::FindWindow(L"DEVIL_MAY_CRY_4",NULL);
	if (nCode<0 || hwnd==NULL)
	{
		return CallNextHookEx(hHook,nCode,wParam,lParam);
	}
	if(wParam==WM_KEYDOWN)
		switch(l->vkCode)
	{
		case VK_F1:dmc.OpenDMC();break;
		case VK_F2:dmc.LockDevil();break;
		case VK_F3:dmc.LockHealth();break;
		case VK_F4:dmc.StopTime();break;		
		case VK_F5:dmc.AutoCharge();break;
		case VK_F6:dmc.KbWalk();break;
		case VK_F7:dmc.MissionC();break;
		case VK_F8:dmc.AllMision();break;
		case VK_F9:dmc.HideHP();break;
		case VK_F10:dmc.AutoSword();;break;
		case VK_F11:dmc.DirectAct();break;
		case VK_F12:dmc.SwordALL();dmc.Pts();break;

		case VK_HOME:dmc.LoadorWrite();break;
		case VK_END:dmc.LoadorWrite(0);break;
		case VK_DELETE:dmc.PauseCamera();break;

	}
	//if	(l->vkCode>=0x60 && l->vkCode<=0x6F)			
	//	return 1;
	//else
	return CallNextHookEx(hHook,nCode,wParam,lParam);
}
void SetHook()
{
	hHook=SetWindowsHookEx(WH_KEYBOARD_LL,KeyProc,GetModuleHandle(NULL),NULL);
}
void StopHook()
{
	if(hHook)
		UnhookWindowsHookEx(hHook);
}

void CDevilMayCry4_DX9Dlg::OnDestroy()
{
	CDialog::OnDestroy();
	dmc.StopThread();
	StopHook();
}


void CDevilMayCry4_DX9Dlg::OnEnChangeEditBP()
{
	UpdateData(TRUE);
	dmc.SetBp(exitBP);
	UpdateData(FALSE);
}


void CDevilMayCry4_DX9Dlg::OnBnClickedHelp()
{
	CString M(_T("Home键:从文件重新读取镜头数据\n\
				 End键:将修改器内数据保存到文件\nPS:\n\
				 @1:修改器和xls文件要在同一文件夹里！！修改器运行会自动读取数据\n\
				 @2:xls中保存的是镜头参数，第一列是动作代码，尽量不要改！\n\
				 @3:用Excel修改xls中的参数，保存并关闭此文件后再按Home键读取数据，不关闭文件会读取失败。。\n其他都很简单了！！"));
	MessageBox(M);
}
